package net.adetech.crj.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.adetech.crj.bean.PaperProgress;
import net.adetech.crj.utils.ApiUtils;
import net.adetech.crj.utils.InnerServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("paper.getProgressListByYwbh")
public class GetPaperProgressListByYwbhService implements BaseService {
    @Autowired
    ApiUtils apiUtils;

    @Override
    public Map<String, Object> invoke(Map<String, Object> params) {
        String ywbh = (String) params.get("ywbh");
        JSONObject args = new JSONObject();
        args.put("ywbh", ywbh);
        args.put("rylb","R");

        List<PaperProgress> paperProgressList = new ArrayList<PaperProgress>();
        JSONObject jsonObject = apiUtils.call("sq_queryApplyProgress", args);
        int success = jsonObject.getInteger("success");
        if (success==1)
        {
            JSONArray progressArray = jsonObject.getJSONObject("data").getJSONArray("list");
            for (int i = 0; i < progressArray.size(); i++) {
                JSONObject progressJson = progressArray.getJSONObject(i);
                String xm = progressJson.getString("xm");
                ywbh = progressJson.getString("ywbh");
                String bzjd = progressJson.getString("bzjd");
                String bzjd_text = progressJson.getString("bzjd_text");
                String emsdh = progressJson.getString("emsdh");
                String slrq = progressJson.getString("slrq");
                String zjzl = progressJson.getString("zjzl");
                PaperProgress paperProgress = new PaperProgress();
                paperProgress.setBzjd(bzjd);
                paperProgress.setBzjd_text(bzjd_text);
                paperProgress.setEmsdh(emsdh);
                paperProgress.setSlrq(slrq);
                paperProgress.setXm(xm);
                paperProgress.setYwbh(ywbh);
                paperProgress.setZjzl(zjzl);
                paperProgressList.add(paperProgress);
            }
        }



        return InnerServiceUtil.buildResult("progressList",paperProgressList);
    }
}
